package com.zhoujiulong.assembly_b.testmvvm.repository

import com.zhoujiulong.assembly_b.testmvvm.ApiService.TestService
import com.zhoujiulong.baselib.base.BaseRepository
import com.zhoujiulong.baselib.http.HttpUtil
import com.zhoujiulong.baselib.http.listener.RequestListener
import com.zhoujiulong.baselib.http.response.DataResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import javax.inject.Inject

/**
 * @Description:
 * @Author:  lfc
 * @Email:    iamlifuchang@163.com
 * @CreateTime:     2021/4/13 14:17
 * @UpdateRemark:
 */
class TestRepository @Inject constructor() : BaseRepository<TestService>() {
    override fun initService(): TestService {
        return HttpUtil.getService(TestService::class.java)
    }

    fun requestTest1(listener: RequestListener<DataResponse<String>>) {
        HttpUtil.sendRequest(mScope, mService.test1(""), listener)
    }

    fun requestTest2(): Flow<DataResponse<String>> {
        return flow {
            val response = mService.test2("")
            emit(response)
        }
            .retry(1)
            .flowOn(Dispatchers.IO)
            .catch {

            }


//        HttpUtil.sendRequest(mScope, mService.test1(""), listener)
    }

}